package cn.qingyun.gis.modules.init.system.shiro.core.exception;

import cn.qingyun.gis.common.Result;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.AuthorizationException;
import org.apache.shiro.authz.UnauthorizedException;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;

/**
 * @author : chenwei
 * @version V1.0
 * @Project: qingyun-boot
 * @Description: TODO
 * @date Date : 2021年01月23日 20:05
 */
@Slf4j
public class ShiroExceptionHandler {
    @ExceptionHandler({UnauthorizedException.class, AuthorizationException.class})
    @ResponseStatus(HttpStatus.OK)
    public Result<?> handleAuthorizationException(AuthorizationException e) {
        log.error(e.getMessage(), e);
        return Result.refuse("没有权限，请联系管理员授权");
    }

}
